|
|
- Mindstorms -- programming with leJOS
import josx.platform.rcx.*;
import josx.robotics.*;
class MoveForward implements Behavior{
public Sensor sensor = Sensor.S2;
public boolean takeControl() {
if (sensor.readValue() <= 45 &&
sensor.readValue() >= 42) return true;
else return false;
}
public void suppress() {}
public void action(){
Motor.C.forward(); Motor.A.forward();
try { Thread.sleep(200); } catch (Exception e) {}
}
}
MoveForward takes control when the reading is between 42-45, and moves the motors forward.
While this may seem like a lot of work.. think about how easy it is to add new behaviors!
It also seperates out the action from why it's being called.
|
|